package com.ztom.test

import cn.hutool.core.io.IoUtil
import com.ztom.core.io.DefaultResourceLoader
import kotlin.test.Test

/**
 * @author ZhangTao
 */
class Test04ResourceLoader {

    @Test
    fun test() {
        val resourceLoader = DefaultResourceLoader()

        // classpath
        val classpathResource = resourceLoader.getResource("classpath:ResourceLoaderTest.txt")
        val classpathStream = classpathResource.getInputStream()
        val classpathContent = IoUtil.readUtf8(classpathStream)
        println("classpath file content: $classpathContent")

        // fileSystem
        val fileSystemResource = resourceLoader.getResource("src/test/resources/ResourceLoaderTest.txt")
        val fileSystemStream = fileSystemResource.getInputStream()
        val fileSystemContent = IoUtil.readUtf8(fileSystemStream)
        println("fileSystem file content: $fileSystemContent")

        // URL
        val urlResource = resourceLoader.getResource("https://www.baidu.com")
        val urlStream = urlResource.getInputStream()
        val urlContent = IoUtil.readUtf8(urlStream)
        println("url file content: $urlContent")
    }
}